﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TetrisShape
{
    public class InputHandler
    {
        public event EventHandler MoveLeft;
        public event EventHandler MoveRight;
        public event EventHandler SpeedUp;
        public event EventHandler Rotate;

        public void QueryKeyBoard()
        {
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo kInfo = Console.ReadKey(true);

                switch (kInfo.Key)
                {
                    case ConsoleKey.LeftArrow:
                        OnMoveLeft();
                        break;
                    case ConsoleKey.RightArrow:
                        OnMoveRight();
                        break;
                    case ConsoleKey.DownArrow:
                        OnSpeedUp();
                        break;
                    case ConsoleKey.UpArrow:
                        OnRotate();
                        break;
                }
            }
        }

        protected virtual void OnMoveLeft()
        {
            if (this.MoveLeft != null)
                this.MoveLeft(this, EventArgs.Empty);
        }

        protected virtual void OnMoveRight()
        {
            if (this.MoveRight != null)
                this.MoveRight(this, EventArgs.Empty);
        }

        protected virtual void OnSpeedUp()
        { 
            if (this.SpeedUp != null)
                this.SpeedUp(this, EventArgs.Empty);
        }

        protected virtual void OnRotate()
        {
            if (this.Rotate != null)
                this.Rotate(this, EventArgs.Empty);
        }
    }
}
